home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-07 | 2.9 KB | 139 lines | [TEXT/R*ch] |
- /*
- ** Copyright: © Michael S. Engber, 1994. All Rights Reserved.
- **
- ** DataUtils.f
- **
- ** Utilities used to manipulate Data.f
- **
- */
-
- //
- // utils for array of frames rep
- //
-
- //Frames created by this fn all share a common map.
- func MakeDataFrame(s1,s2,s3,s4)
- {slot1: s1, slot2: s2, slot3: s3, slot4: s4};
-
- //Clone entire data set to use a common map
- func CloneWithCommonMap(data)
- begin
- local newData := Clone(data);
- local i,elt;
- foreach i,elt in newData do
- newData[i] := MakeDataFrame(elt.slot1,elt.slot2,elt.slot3,elt.slot4);
- return newData;
- end;
-
-
-
- //
- // utils for array of arrays rep
- //
-
- func MakeDataArray(s1,s2,s3,s4)
- [s1, s2, s3, s4];
-
- func DataToArrays(data)
- begin
- local newData := Clone(data);
- local i,elt;
- foreach i,elt in newData do
- newData[i] := MakeDataArray(elt.slot1,elt.slot2,elt.slot3,elt.slot4);
- return newData;
- end;
-
-
- //
- // utils for frame of frames rep
- //
-
- func MakeSubDataFrame(s1,s2,s3,s4)
- {slot1: s1, slot3: s3, slot4: s4};
-
- func DataToFrame(data)
- begin
- local newData := {};
- local i,elt;
- foreach i,elt in data do
- newData.(Intern(elt.slot2)) := MakeSubDataFrame(elt.slot1,elt.slot2,elt.slot3,elt.slot4);
- return newData;
- end;
-
-
- //
- // utils for binary object rep
- //
-
- constant kSlot1Offset := 0; //a long (4 bytes)
- constant kSlot2Offset := 4; //a cstring of (8 bytes = up to 7 chars + terminating null)
- constant kSlot3Offset := 12; //a word (2 bytes)
- constant kSlot4Offset := 14; //a byte
- constant kDatumSize := 15;
-
- func PutDatum(binObj,offset,s1,s2,s3,s4)
- begin
- StuffLong (binObj,offset + kSlot1Offset, s1);
- StuffCString(binObj,offset + kSlot2Offset, s2);
- StuffWord (binObj,offset + kSlot3Offset, s3);
- StuffByte (binObj,offset + kSlot4Offset, if s4 then 1 else 0);
- end;
-
- func GetDatum(binObj,offset)
- {
- slot1: ExtractLong(binObj,offset + kSlot1Offset),
- slot2: ExtractCString(binObj,offset + kSlot2Offset),
- slot3: ExtractWord(binObj,offset + kSlot3Offset),
- slot4: ExtractByte(binObj,offset + kSlot4Offset) <> 0,
- };
-
-
- func DataToBinObj(data)
- begin
-
- binObj := SetLength("",Length(data)*kDatumSize);
-
- local i,elt;
- foreach i,elt in data do
- PutDatum(binObj,i*kDatumSize,elt.slot1,elt.slot2,elt.slot3,elt.slot4);
-
- return binObj;
- end;
-
-
-
-
- //
- // utils for soups
- //
-
- DefConst('kMakeSoupFn,func(soupName,arrayOfFrames,indexPath,indexType)
- begin
- local store := GetStores()[0];
-
- if store:HasSoup(soupName) then
- store:GetSoup(soupName):RemoveFromStore();
-
- local initialUsedSize := store:UsedSize();
-
- local soup := store:CreateSoup(soupName,[{structure: 'slot, path: indexPath, type: indexType}]);
-
- local i,elt;
- local str := $/ & Length(arrayOfFrames) & $\n;
- //need to clone - arrayOfFrames is most likely read-only
- foreach i,elt in arrayOfFrames do
- begin
- soup:Add(Clone(elt));
- if i MOD 10 = 0 then
- begin
- Write(i);
- Write(str);
- end;
- end;
-
- Print("soup \"" & soupName & "\" created (" & store:UsedSize() - initialUsedSize && "bytes)");
-
- soup;
- end
- );
-